//
//  MZDecimalDemoViewController.m
//  MZBaseDemo
//
//  Created by Chris Yang on 2016/12/5.
//  Copyright © 2016年 Chris Yang. All rights reserved.
//

#import "MZDecimalDemoView.h"
#import "MZDecimalDemoModel.h"

#import "MZDecimalDemoViewController.h"

@interface MZDecimalDemoViewController ()
<MZDecimalDemoModelDelegate,
MZDecimalDemoViewDelegate>

@property (nonatomic, strong) MZDecimalDemoView *demoView;
@property (nonatomic, strong) MZDecimalDemoModel *viewModel;

@end

@implementation MZDecimalDemoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self settingBase];
    [self settingSubviews];
    
    [_viewModel setCurOpType:MZDemoOpTypeAdd];
}

- (void)settingBase {

    _viewModel = [[MZDecimalDemoModel alloc] init];
    [_viewModel setDelegate:self];
}

- (void)settingSubviews {
    
    _demoView = [[MZDecimalDemoView alloc] init];
    [_demoView setDelegate:self];
    
    [self.view addSubview:_demoView];
    [_demoView setFrame:self.view.bounds];
}

#pragma mark - MZDecimalDemoModelDelegate

- (void)demoModel:(MZDecimalDemoModel *)model didUpdateOpType:(MZDemoOpType)opType {
    [_demoView updateOpString:[_viewModel typeStrOfType:opType]];
}

#pragma mark - MZDecimalDemoViewDelegate

- (void)demoView:(MZDecimalDemoView *)view buttonClickedAtIndex:(NSInteger)index {
    
    if (0 == index) {
        /* 操作符号 */
        UIAlertController *tmpAc = [_viewModel opTypeSettingActionSheet];
        [self presentViewController:tmpAc animated:YES completion:nil];
        
    } else if (1 == index) {
        /* 右值为Decimal的运算 */
        NSString *calcResult = [_viewModel decimalCalcWithLeftStr:view.leftVal rightStr:view.rightVal];
        [_demoView updateResult:calcResult];
        
    } else if (2 == index) {
        /* 右值为String的运算 */
        NSString *calcResult = [_viewModel stringCalcWithLeftStr:view.leftVal rightStr:view.rightVal];
        [_demoView updateResult:calcResult];
        
    } else if (3 == index) {
        /* 右值为Number的运算 */
        NSString *calcResult = [_viewModel numberCalcWithLeftStr:view.leftVal rightStr:view.rightVal];
        [_demoView updateResult:calcResult];
        
    } else if (4 == index) {
        /* 小数点位数 */
        NSInteger randScale = rand() % 6;
        NSString *formattedStr = [_viewModel roundingStrFromValString:view.resultVal scale:randScale];
        [view updateScale:randScale];
        [view updateResult:formattedStr];
        
    } else if (5 == index) {
        /* 基础测试 */
        
    }
}

#pragma mark -

@end
